﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Example_aliasing_and_Arrays
{
    public partial class Form1 : Form
    {
        private BankAccount b1, b2, b3;
        private BankAccount currentAccount;

        private School mySchool;

        public Form1()
        {
            InitializeComponent();

            b1 = new BankAccount(2003, "Arnold", 50);
            b2 = new BankAccount(2004, "Bert", 200);
            b3 = new BankAccount(2005, "Carla", 100);

            this.radioButton1.Text = b1.Name;
            this.radioButton2.Text = b2.Name;
            this.radioButton3.Text = b3.Name;

            this.radioButton1.Checked = true;
            currentAccount = b1;
        }

        private void btnWithdraw_Click(object sender, EventArgs e)
        {

            currentAccount.Withdraw(Convert.ToDecimal(this.tbMoney.Text));
            this.lbInfo.Items.Clear();
            this.lbInfo.Items.Add("Withdrawal performed for:");
            this.lbInfo.Items.Add("acc. nr: " + currentAccount.Accountnumber.ToString());
            this.lbInfo.Items.Add("name: " + currentAccount.Name);
            this.lbInfo.Items.Add("new balance: " + currentAccount.Balance.ToString());

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton1.Checked)
            {
                MessageBox.Show("Bankaccount b1 is choosen");
                currentAccount = b1;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton2.Checked)
            {
                MessageBox.Show("Bankaccount b2 is choosen");
                currentAccount = b2;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton3.Checked)
            {
                MessageBox.Show("Bankaccount b3 is choosen");
                currentAccount = b3;
            }
        }

        private void btnCreateSchool_Click(object sender, EventArgs e)
        {
            int nrOfStudents = Convert.ToInt32(this.tbNrOfStudents.Text);
            this.mySchool = new School(this.tbName.Text, nrOfStudents);
        }

        private void btnFillWithRandomNumbers_Click(object sender, EventArgs e)
        {
            mySchool.fillArrayCompletelyWithRandomNumbers();
        }

        private void btnHowManyHaveThisMark_Click(object sender, EventArgs e)
        {
            int interestingMark = Convert.ToInt32(this.tbMark.Text);
            int answer = this.mySchool.countFrequencyOfACertainMark(interestingMark);
            MessageBox.Show(answer.ToString());
        }

        private void btnShowFrequencies_Click(object sender, EventArgs e)
        {
            //todo
        }

        private void btnShowIt_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Add(this.mySchool.Name);
            for(int i = 0 ; i< mySchool.NrOfElements; i++)
            {
                this.listBox1.Items.Add(
                    "number " + i.ToString() + " is " +
                    this.mySchool.getNumber(i).ToString());
            }
        }

    }
}
